<template>
	<view class="content">
		<view class="banner">
			<u-swiper :list="banner_list" indicator="false" height="200" :loading="loading"></u-swiper>
		</view>
		<view class="search">
			<u-search placeholder="搜索小区名" animation="true" @search="btn_click_search" :showAction="false"
				v-model="keyword" bgColor="#fff">
			</u-search>
		</view>
		<view class="nav">
			<u-grid :border="false" @click="clickNav" col="4">
				<u-grid-item bgColor="#f4f4f4;" v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
					<img :src="baseListItem.img" alt="" class="nav-img">
					<text class="grid-text">{{baseListItem.title}}</text>
				</u-grid-item>
			</u-grid>
			<u-toast ref="uToast" />
		</view>
		<view class="notice">
			<view class="icon">
				房产头条
			</view>
			<view class="notices">
				<u-notice-bar :text="notice" direction="column" bgColor="#fff" color="#000" @click="showtoutiao = true">
				</u-notice-bar>
			</view>
			<u-overlay :show="showtoutiao" @click="showtoutiao = false">
				<view
					style="width: 90%;margin: 0 auto;height: 200px;background: white;position: relative;top: 30%;border-radius: 5px;">
					<view style="justify-content: center;font-size: 18px;display: flex;margin: 20px 20px 10px 20px;">
						房产头条</view>
					<view style="border:2px solid #007AFF;width: 50%;margin: 0 auto;"></view>
					<view style="height: 140px;overflow-x: hidden;overflow-y: scroll;">
						<view v-for="(item,index) in notice" :key="index"
							style="padding: 5px;margin-top:5px;font-size: 14px;margin-left: 5px;align-content:center">
							{{index+1}}.{{item}}</view>
					</view>
				</view>
			</u-overlay>
		</view>
		<view class="tabs">
			<u-tabs :list="tabs_list" @click="clickTabs" sticky :current="tabs_current" :activeStyle="{
				color:'#3993d1'
			}" lineColor="#3993d1" scrollable="false" itemStyle="padding-top:10px;padding-bottom:10px;"></u-tabs>

			<u-tabs :list="tabs_lists" @click="clickTabsLists" :current="tabs_currents" :activeStyle="{
				color:'#3993d1',
				background:'#ebf3f9',
				padding:'10px 30px'
			}" lineColor="#3993d1" scrollable="false" itemStyle="padding-top:10px;padding-bottom:10px;"></u-tabs>
		</view>
		<view class="con">
			<u-empty mode="data" v-if="emptyData"></u-empty>
			<view class="item" @click="btn_click_dia(item.id)" v-else v-for="(item,index) in index_list" :key="index">
				<view class="left">
					<image :src="item.logo[0].img_file" mode=""></image>
				</view>
				<view class="right">
					<view class="title">{{item.title}}</view>
					<view class="desc">{{item.room}}室{{item.office}}厅/{{item.area}}m²/{{item.community_name}}</view>
					<view class="money">
						<view class="mon">{{item.money}}<text v-if="type_index == 1">万</text><text v-else>元</text>
						</view>
						<view class="text" v-if="type_index == 1">{{item.art}}元/平</view>
					</view>
					<view class="address">
						<view class="icon">
							<u-icon name="map"></u-icon>
						</view>
						<view class="text">
							{{item.address}}
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				title: 'Hello',
				banner_list: [],
				banner_current: 0,
				baseList: [],
				notice: [],
				tabs_list: [{
					name: '中介房源',
				}, {
					name: '个人房源',
				}],
				tabs_current: 0,
				tabs_lists: [{
					name: '买房'
				}, {
					name: '租房'
				}],
				tabs_currents: 0,
				listData: [],
				limit: 10,
				page: 1,
				house_type: 1,
				source: '中介房源',
				index_list: [],
				emptyData: false,
				root_path: getApp().globalData.root_url,
				loading: true,
				type_index: 1,
				showtoutiao: false
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onLoad() {
			this.loadCate();
			this.loadIndex();
			this.loadNotice();
			this.getlocation();
		},
		onShow() {
			this.banner_list = [];
			this.loadData();
		},
		methods: {
			getlocation() {
				let that = this;
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						uni.setStorageSync('lng', res.longitude);
						uni.setStorageSync('lat', res.latitude);
					}
				});
			},
			bannerChange(e) {
				this.banner_current = e.current;
			},
			shownotice(e, index) {
				console.log(e)
				console.log(index)
			},
			clickTabs(e) {
				console.log(e)
				this.tabs_current = e.index
				this.source = e.name
				this.index_list = [];
				this.loadIndex();
			},
			clickTabsLists(e) {
				this.tabs_currents = e.index;
				if (e.index == 0) {
					this.house_type = 1;
					this.type_index = 1;

				} else {
					this.house_type = 2;
					this.type_index = 2;
				}

				this.index_list = [];
				this.loadIndex();
			},
			async loadData() {
				let that = this;
				that.http("applet_banner_index", {
					"type": 1
				}).then(res => {
					console.log(res.data)
					if (res.ec == 200) {
						this.loading = false;
						res.data.forEach(function(item, index) {
							let lists = getApp().globalData.root_url + item.img_file;
							that.banner_list.push(lists)
						})
					}
				})
			},
			async loadCate() {
				let that = this;
				that.http("applet_cate_index").then(res => {
					console.log(res.data)
					if (res.ec == 200) {
						if (res.data.cate.length != 0) {
							let root_url = getApp().globalData.root_url;
							res.data.cate.forEach(function(item, index) {
								that.baseList.push({
									img: root_url + item.img_file,
									title: item.title,
									type: item.type
								})
							})
						}
					}
				})
			},
			async loadIndex() {
				let that = this;
				that.http("applet_house_Index_get", {
					house_type: that.house_type,
					source: that.source,
					limit: that.limit,
					page: that.page,
					lng: uni.getStorageSync('lng'),
					lat: uni.getStorageSync('lat')
				}).then(res => {
					if (res.ec == 200) {
						if (res.data.lists.length == 0) {
							this.emptyData = true;
						} else {
							this.emptyData = false;
						}
						res.data.lists.forEach(function(item, index) {
							that.index_list.push(item)
						})
					}
				})
			},
			async loadNotice() {
				let that = this;
				that.http("applet_house_notice_list").then(res => {
					if (res.ec == 200) {
						that.notice = res.data.notice
					}
				})
			},
			btn_click_dia(id) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id + "&type_index=" + this.type_index,

				})
			},
			clickNav(index) {
				uni.navigateTo({
					url: '/pages/Intermediary/Intermediary?title=' + this.baseList[index]['title'],
				})
			},
			btn_click_search(e) {
				uni.navigateTo({
					url: '/pages/search/search?search=' + e
				})
			}
		},
		onShareAppMessage() {
			return {
				title: '南因房产',
				path: '/pages/index/index'
			}
		},
		onShareTimeline() {
			return {
				title: '南因房产',
				path: '/pages/index/index'
			}
		}

	}
</script>

<style lang="scss">
	.banner {
		position: relative;
	}

	.search {
		width: 100%;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #f4f4f4;
		height: 68rpx;
		position: relative;

		.u-search {
			width: 80%;
			position: absolute;
			top: -34rpx;
		}
	}

	.nav {
		padding-bottom: 20rpx;
		background: #f4f4f4;

		.nav-img {
			width: 80rpx;
			height: 80rpx;
			margin: 20rpx 0;
		}
	}

	.notice {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;

		.icon {
			color: #357bca;
			letter-spacing: 5rpx;
			margin: 0 10rpx;
			font-size: 40rpx;
		}

		.notices {
			flex: 1;
		}
	}

	.tabs {
		border-top: 20rpx solid #f4f4f4;
	}

	.con {
		display: flex;
		flex-direction: column;

		.item {
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			padding-bottom: 10rpx;
			padding-top: 10rpx;
			border-bottom: 1rpx solid #f0f0f0;

			.left {
				width: 250rpx;
				height: 181rpx;
				overflow: hidden;
				margin: 0 20rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				flex: 1;

				.title {
					font-size: 28rpx;
					font-weight: 600;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					width: 99%;
				}

				.desc {
					font-size: 26rpx;
					margin: 10rpx 0;
					max-width: 98%;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.money {
					display: flex;
					flex-direction: row;
					margin: 10rpx 0;

					.mon {
						font-size: 30rpx;
						color: #eb584e;
						font-weight: 600;
					}

					.text {
						font-weight: 24rpx;
						color: #959595;
						margin-left: 10rpx;
					}
				}

				.address {
					display: flex;
					flex-direction: row;
					font-size: 24rpx;
					color: #959595;
				}
			}
		}
	}
</style>
